package com.cmii.sjw.department.control.jsc.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.cmii.sjw.department.control.jsc.model.params.AuthClientParams;
import com.cmii.sjw.department.control.jsc.service.AuthClientService;
import com.cmii.sjw.department.control.jsc.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 统一鉴权业务协同网关
 * @author jfh
 * @date 2024-11-12 周二 16:00
 * @version 1.0
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/authClient")
public class AuthClientController {

    @Autowired
    private AuthClientService authClientService;

    /**
     * 数智强师鉴权网关
     * @param params 数智强师token
     * @return 鉴权结果
     */
    @PostMapping("/authSzqs")
    public Result<SaTokenInfo> authSzqs(@RequestBody AuthClientParams params) {
        log.info("dcqcTk:{}", params);
        if (StringUtils.isEmpty(params.getDcqcTk())) {
            return Result.error("dcqcTk不能为空");
        }
        return authClientService.authSzqs(params.getDcqcTk());
    }

    /**
     * 惠学生鉴权网关
     * @param params 惠学生token
     * @return 鉴权结果
     */
    @PostMapping("/authHxs")
    public Result<SaTokenInfo> authHxs(@RequestBody AuthClientParams params) {
        log.info("dcqcTk:{}", params);
        if (StringUtils.isEmpty(params.getDcqcTk())) {
            return Result.error("dcqcTk不能为空");
        }
        return authClientService.authHxs(params.getDcqcTk());
    }

    /**
     * 校园智治鉴权网关
     * @author jfh
     * @Date 2025/5/30 9:48
     * @param params 校园智治token
     * @return com.cmii.sjw.department.control.jsc.util.Result<cn.dev33.satoken.stp.SaTokenInfo>
     */
    @PostMapping("/authXyzz")
    public Result<SaTokenInfo> authXyzz(@RequestBody AuthClientParams params) {
        log.info("dcqcTk:{}", params);
        if (StringUtils.isEmpty(params.getDcqcTk())) {
            return Result.error("dcqcTk不能为空");
        }
        return authClientService.authXyzz(params.getDcqcTk());
    }
}
